package com.xiaoyu.client.ui.activity.main.mine.wallet_and_member;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xiaoyu.client.R;
import com.xiaoyu.client.model.mine.MemberVipBean;
import com.xiaoyu.client.model.mine.ParticularsBean;

import java.util.List;

/**
 * @author jx
 * @date 创建时间 2018/10/17
 * @Description
 */
public class MemberGridViewAdapter extends BaseAdapter {
    private Context context;
    private List<MemberVipBean.DataBean.ViptypelsitBean> mMemberList;

    public MemberGridViewAdapter(Context context, List<MemberVipBean.DataBean.ViptypelsitBean> mList) {
        this.context = context;
        this.mMemberList = mList;
    }

    @Override
    public int getCount() {
        return mMemberList.size();
    }

    @Override
    public Object getItem(int i) {
        return mMemberList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        GridViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.member_gridview_item, null);
            holder = new GridViewHolder();
            holder.mLinear = view.findViewById(R.id.member_gridview_item_linear);
            holder.mName = view.findViewById(R.id.viptypename);
            holder.mMoney = view.findViewById(R.id.member_gridview_money);
            holder.mAward = view.findViewById(R.id.member_gridview_award);
            view.setTag(holder);
        } else {
            holder = (GridViewHolder) view.getTag();
        }
        //处理逻辑
        MemberVipBean.DataBean.ViptypelsitBean params = mMemberList.get(i);
        holder.mName.setText(params.getViptypename());
        holder.mMoney.setText("¥ " + params.getViptypemoney());
        holder.mAward.setText("+" + params.getGivemoney() + "奖励");
        //选中某一个之后背景颜色改变
        if (clickTemp == i) {
            holder.mLinear.setBackgroundResource(R.mipmap.mine_bg_chongzhika);
        } else {
            holder.mLinear.setBackgroundResource(R.mipmap.mine_bg_chongzhika_gray);
        }

        return view;
    }

    private int clickTemp = -1;

    public void setSelection(int position) {
        clickTemp = position;
    }

    private class GridViewHolder {
        private LinearLayout mLinear;
        private TextView mMoney;
        private TextView mAward;
        private TextView mName;
    }

}

